extends Control
class_name InputControl

var isHover = false


func _physics_process(delta):
	processInput()
		

func processInput():
	if not visible or not GlobalData.uiAcceptInput: return
	
	if Input.is_action_just_pressed("mouse_left_button"):
		var mousePosition = Global.getMousePosition()
		if mousePosition.x <= global_position.x + size.x and mousePosition.x >= global_position.x and mousePosition.y <= global_position.y + size.y and mousePosition.y >= global_position.y:
			if self.has_method("onMouseLeftButtonPressed"):
				self.call("onMouseLeftButtonPressed")
				
	var mViewPosition = Global.getMousePosition()
	if mViewPosition.x <= global_position.x + size.x and mViewPosition.x >= global_position.x and mViewPosition.y <= global_position.y + size.y and mViewPosition.y >= global_position.y:
		isHover = true
		if self.has_method("onMouseHover"):
			self.call("onMouseHover", mViewPosition)
	else:
		if isHover:
			isHover = false
			if self.has_method("onMouseHoverOut"):
				self.call("onMouseHoverOut")
	
